package com.five.bi.controller;

import com.five.bi.model.request.ListDataSetRequest;
import com.five.bi.model.request.SaveDataSetRequest;
import com.five.bi.service.DataSetService;
import com.five.bi.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description
 * @Author xuzhihong
 * @Version 1.0
 * @Date 2022/8/2
 */
@RestController()
@RequestMapping("/api/v1/dataset")
public class DataSetController {

    @Autowired
    private DataSetService dataSetService;

    /**
     * 创建数据集
     * @param saveDataSetRequest
     * @return
     */
    @PostMapping("/create")
    public JsonData save(@RequestBody SaveDataSetRequest saveDataSetRequest, HttpServletRequest request){

        String dataSetId = dataSetService.save(saveDataSetRequest,request);
        Map<String, String> data = new HashMap<>(1);
        data.put("dataSetId",dataSetId);

        return JsonData.buildSuccess(data);
    }

    /**
     * 数据集列表
     * @param listDataSetRequest
     * @return
     */
    @PostMapping("/list")
    public JsonData list(@RequestBody ListDataSetRequest listDataSetRequest){

        Map<String, Object> data = dataSetService.list(listDataSetRequest);

        return JsonData.buildSuccess(data);
    }

    @GetMapping("/delete")
    public JsonData delete(@RequestParam String id){
         dataSetService.deleteById(id);
            return JsonData.buildSuccess("删除成功！");
    }

    /**
     * 数据集信息
     * @param dataSetId
     * @return
     */
    @GetMapping("/info/{dataSetId}")
    public JsonData list(@PathVariable("dataSetId") String dataSetId){

        Map<String, Object> data = dataSetService.info(dataSetId);

        return JsonData.buildSuccess(data);
    }
}
